﻿ <?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Manager Ajax Users View
***********************************************************/
?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php include_once "../../model/SessionModel.php"; ?>
<?php include_once "../../model/DevelopperModel.php"; ?>
<?php session_start(); ?>

<div class="section_title" id="objects"><h1> Méthodes </h1></div>
<div class="section_info">
	Obtention des renseignements sur les types de méthodes, les listes des méthodes, et l'affichage des instructions des méthodes.
</div>

<div class="article">

<div class="section_title_small_blue"><h4>Sélectionnez un type de méthode</h4></div>

<table class="tableQueryCenter">
	<tr>
		<th>Type d'objet</th>
		<th>Nombre</th>
		<th>Afficher</th>
	</tr>
<?php
	$nbRow = DevelopperModel::getFunctionTypes($_SESSION['session']->currentConnection, $result);
	
	if(isset($_GET['selected_type']))
		$selectedType = $_GET['selected_type'];
	
	foreach ($result as $row) {
		echo "<tr>";
		echo "<td>".$row['OBJECT_TYPE']."</td>\n";
		echo "<td>".$row['COUNT(OBJECT_TYPE)']."</td>\n";
		
		if(isset($selectedType) && $selectedType == $row['OBJECT_TYPE'])
		{
			?><td><img src="img/check.png" alt="check" /></td><?php
		}
		else
		{
			?><td><a href="#objects"><img src="img/find.png" alt="zoom" onClick="displayFunctions('<?php echo $row['OBJECT_TYPE'] ?>')" /></a></td><?php
		}
		
		
		echo"</tr>";
	}
?>
</table>

<br />

<?php
if(isset($selectedType))
{
	$nbRow2 = DevelopperModel::getObjects($_SESSION['session']->currentConnection, $result2, $selectedType, $columns);
	
	if(isset($_GET['selected_name']))
		$selectedFunction = $_GET['selected_name'];
	
	?>
	
	<div class="section_title_small_green"><h4><?php echo $selectedType ?></h4></div>
	
	<div class="section_title_small_blue"><h4>Sélectionnez une méthode</h4></div>
	
	<table class="tableQueryCenter">

	<tr>
		<th>ID</th>
		<th>Nom</th>
		<th>Création</th>
		<th>Utilisation</th>
		<th>Namespace</th>
		<th>Afficher</th>
	</tr>

	<?php
	
	foreach ($result2 as $row2) {
		echo "<tr>";
		echo "<td>".$row2['ID']."</td>\n";
		echo "<td>".$row2['NOM']."</td>\n";
		echo "<td>".$row2['CREATION']."</td>\n";
		echo "<td>".$row2['UTILISATION']."</td>\n";
		echo "<td>".$row2['NAMESPACE']."</td>\n";
		
		if(isset($selectedFunction) && $selectedFunction == $row2['NOM'])
		{
			?><td><img src="img/check.png" alt="check" /></td><?php
		}
		else
		{
			?><td><a href="#objects"><img src="img/find.png" alt="zoom" onClick="displayFunctions('<?php echo $selectedType ?>', '<?php echo $row2['NOM'] ?>')" /></a></td><?php
		}
		
		echo"</tr>";
	}
	
	?>
	</table>
	<br />

<?php
}
?>

<?php
if(isset($selectedFunction))
{
?>
	<div class="section_title_small_blue"><h4>Code</h4></div>
	
	<div class="sql_code">
	<pre class="sh_sql">
		<?php
		echo "\n";
		$nbRow = DevelopperModel::getFunctionCode($_SESSION['session']->currentConnection, $code, $selectedType, $selectedFunction);
		$lines = "";
		foreach ($code as $l) {
			$lines = $lines.$l['TEXT'];
		}
		echo htmlentities($lines);
		?>
	</pre>
	</div>
	
	<a href="view/main/DownloadView.php?name=Save.sql&text=<?php echo urlencode($lines) ?>" target="_blank"><input type="button" value="Télécharger" /></a>

<?php
}
?>
</div>

<script type="text/javascript" src="js/sql/shjs.js"></script>
<script type="text/javascript" src="js/sql/sh_sql.js"></script>
<script type="text/javascript">

	//JQuery main entry point
	 $(document).ready(function() {
		//Highlight query
		sh_highlightDocument();
	 });
</script>



